import Vue from 'vue'
import VueRouter from 'vue-router'
// import Login from '../views/login.vue'
// import Layout from '../views/layout.vue'
// import Images from '../views/image.vue'
// import Articles from '../views/articles/articles.vue'
// import Edit from '../views/articles/edit.vue'
// import Home from '../views/home.vue'
// import AddArticle from '../views/articles/addArticle.vue'
// import Comments from '../views/comments.vue'
// import Fans from '../views/fans.vue'
const Login = () => import(/* webpackChunkName: "login" */ '../views/login.vue')

const Layout = () => import(/* webpackChunkName: "Layout" */ '../views/layout.vue')

const Images = () => import(/* webpackChunkName: "Images" */ '../views/image.vue')

const Articles = () => import(/* webpackChunkName: "Articles" */ '../views/articles/articles.vue')

const Home = () => import(/* webpackChunkName: "Home" */ '../views/home.vue')

const Edit = () => import(/* webpackChunkName: "Edit" */ '@/views/articles/edit.vue')

const AddArticle = () => import(/* webpackChunkName: "AddArticle" */ '@/views/articles/addArticle.vue')

const Comments = () => import(/* webpackChunkName: "Comments" */ '@/views/comments.vue')

const Fans = () => import(/* webpackChunkName: "Fans" */ '@/views/fans.vue')
Vue.use(VueRouter)

const router = new VueRouter({
  // 配置路由
  routes: [
    // 登陆
    { path: '/login', component: Login },
    // 主页
    {
      path: '/',
      component: Layout,
      children: [
        // { path: '' },
        { path: '', component: Home },
        { path: '/articles', component: Articles },
        { path: '/image', component: Images },
        { path: '/addArticle', component: AddArticle },
        // 这是动态路由，会匹配所有deit/xxxx的格式
        { path: '/edit/:id', component: Edit },
        { path: '/comment', component: Comments },
        { path: '/fans', component: Fans }
      ]
    }
  ]
})
// const vipPages = ['/', '/articles', '/images']
// router.beforeEach((to, from, next) => {
//   const tokenStr = localStorage.getItem('tokenStr')
//   if (vipPages.includes(to.path) && !tokenStr) {
//     next('/login')
//   } else if (to.path === '/login' && tokenStr) {
//     next('/')
//   } else {
//     next()
//   }
// })

export default router
